import handleActions from 'libs/handleActions'

const HANDLER = 'HANDLER'
const UFO = 'UFO'
const defaultHandlers = { [HANDLER]: state => state }
const undefinedHandlers = { [HANDLER]: undefined }
const handlers = { [HANDLER]: state => ++state } // eslint-disable-line
const defaultState = 1
const action = { type: HANDLER }
const ufoAction = { type: UFO }

it('should call handleActions without errors', () => {
  const reducer = handleActions(defaultHandlers)
  const state = reducer(defaultState, action)

  expect(state === defaultState).toBe(true)
})

it('should use the defaultState if do not passing state when calling reducer', () => {
  const reducer = handleActions(defaultHandlers, defaultState)
  const state = reducer(undefined, ufoAction)

  expect(state === defaultState).toBe(true)
})

it('should return the same state if do not passing handler for the corrsponding action type', () => {
  const reducer = handleActions(undefinedHandlers)
  const state = reducer(defaultState, action)

  expect(state === defaultState).toBe(true)
})

it('should update state if passing handler for changing state', () => {
  const reducer = handleActions(handlers)
  const state = reducer(defaultState, action)

  expect(state === defaultState + 1).toBe(true)
})

it('should return the same state if passing UFO action ', () => {
  const reducer = handleActions(defaultHandlers)
  const state = reducer(defaultState, ufoAction)

  expect(state === defaultState).toBe(true)
})
